import { Server } from "socket.io";
import { SocketServer } from "./typing";
import { logger } from "@/utils/log"; // 日志方法
export const socketServer: SocketServer = (server) => {
  const io = new Server(server, {
    // 路径-默认socket.io
    path: "/test",
    // 处理跨域
    cors: {
      origin: "*",
    },
  });

  io.on("connection", (socket) => {
    logger.log("有人连接啦！");
    // 向客户端发送消息
    socket.emit("test", "恭喜你连接成功");
  });
};
